<template>
  <div class="chats">
    <!-- 对话 -->
    <div class="chat" ref="box">
      <div
        v-for="(item, index) in msgList"
        :key="index"
        class="content"
        :class="item.myself ? 'right' : 'left'"
      >
        <div class="init flex">
          <!-- 头像 -->
          <div class="user-photo">
            <img :src="item.photoSrc" />
          </div>
          <!-- /头像 -->

          <!-- 消息内容 -->
          <div class="user-text">
            <span
              v-html="item.message"
              style="word-wrap: break-word; word-break: break-all"
            ></span>
          </div>
          <!-- /消息内容 -->
        </div>
        <!-- 
        <div class="system flex align-center" v-if="item.linkServe">
          <img src="../../assets/images/feedback/tips.png" alt="" /><span
            >本地宝人工客服已接入会话，我们预计三分钟内联系您。</span
          >
        </div> -->
      </div>
    </div>
    <!-- /对话 -->

    <!-- 输入框 -->
    <div class="bottom-input flex">
      <textarea
        class="input-box"
        v-model="inputValue"
        @keydown="enter"
        placeholder="请描述您的问题"
        style="color: #000"
      ></textarea>
      <div class="flex flex-end">
        <button @click="send">发送</button>
      </div>
    </div>
    <!-- /输入框 -->
  </div>
</template>

<script>
export default {
  name: "chat",
  props: {
    msg: String,
  },
  data() {
    return {
      inputValue: "",
      msgList:[]
    };
  },
  methods: {
    send() {
      console.log(this.getNews);
      if (this.inputValue == "") {
        return;
      }
      this.msgList.push({
        message: this.inputValue,
        myself: true,
        photoSrc: require("../assets/images/kefu-photo.png"),
      });
      
      this.inputValue = "";
      this.scrollBottom();
    },
    enter() {
      console.log(123);
    },
    /**
     * 消息自动滚动到底部
     *
     */
    scrollBottom() {
      this.$nextTick(() => {
        let ele = this.$refs.box;
        ele.scrollTop = ele.scrollHeight;
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="stylus">
.chat{
  height 77.5vh
  overflow-y: scroll;
  border-bottom: 1px solid rgba(0.8, 0.85, 0.87, 0.1);
}
.content {
  position: relative;
  justify-content: flex-start;
  padding-bottom: 20px;

  .init {
    margin: 22px 2vw 0 24px;
  }
}

// 用户
.right {
  position: relative;
  justify-content: flex-end;
  font-size: 28px;

  .init {
    flex-direction: row-reverse;
    margin: 22px 22px 0 135px;

    .user-photo {
      img {
        margin: 0 0 0 25px;
      }
    }

    .current-time {
      position: absolute;
      top: 15px;
      right: 110px;
      font-size: 24px;
      color: rgb(153, 153, 153);
    }

    .user-text {
      max-width: 45vw;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      align-items: center;
      padding: 20px 21px;
      border-radius: 5px;
      font-size: 30px;
      color: #333;
      background-color: rgba(0, 110, 255, 0.1);

      span {
        display: inline-block;
        padding: 0;
        font-size: 18px;
        color: #333;
      }
    }
  }
}

// 用户头像
.user-photo img {
  width: 60px;
  height: 60px;
  margin: 0px 25px 0 0px;
  border-radius: 36px;
}

.arrow-left img {
  width: 18px;
  height: 33px;
  margin-top: 30px;
}

// 回复内容&输入内容
.left {
  .init {
    .current-time {
      position: absolute;
      left: 110px;
      top: 15px;
      font-size: 24px;
      color: rgb(153, 153, 153);
    }
    .user-text {
      // width: 41vw;
      padding: 18px 21px;
      border-radius: 5px;
      font-size: 30px;
      color: #333;
      background: rgba(0, 110, 255, 0.03);

      .repeat {
        max-width: 750px;
        justify-content: flex-start;
        flex-wrap: wrap;
        font-size: 30px;
        line-height: 30px;

        .first-word {
          .word-top {
            // max-width: 750px;
            // width: 39vw;
            padding-bottom: 15px;
            border-bottom: 1px solid rgba(0.8, 0.85, 0.87, 0.1);
            .time {
              margin: 0 0 8px 0;
              font-size: 20px;
              font-weight: 700;
              color: #111;
            }
            .word-desc {
              font-size: 18px;
              color: #333;
            }
          }

          .list {
            span {
              font-size: 14px;
              color: #444;
            }

            ul {
              flex-direction: column;
              flex-wrap: wrap;
              min-width: 200px;
              margin: 10px 0 0 0;
              li {
                max-width: 305px;
                .list-index {
                  display: inline-block;
                  margin: 3px 10px 0 0;
                  font-size: 16px;
                  font-weight: 700;
                  color: #8a8b8a;
                }
                .list-item {
                  display: inline-block;
                  margin: 3px 0;
                  font-size: 18px;
                  color: #0066ff;
                }
              }
            }
          }
        }

        .other-word {
          max-width: 750px;

          font-size: 18px;
        }
      }
    }
  }
}

.boot .left:nth-of-type(n + 2) {
  .user-text {
    .repeat {
      flex-direction: column;
      justify-content: flex-start;
      .init-link {
        text-align: center;
      }
    }
  }
}

// 输入框
.bottom-input {
  position: relative;
  height: 18%;
  flex-direction: column;
  justify-content: space-between;
}
.bottom-input button {
  position: relative;
  z-index: 9;
  border-radius: 5px;
  opacity: 1;
  background: rgba(0, 110, 255, 1);
  color: rgba(255, 255, 255, 1);
  font-size: 16px;
  font-weight: 400;
  padding: 8px 27px;
  margin: 10px 31px 10px 0;
}

/deep/ .el-textarea__inner {
  padding: 21px 0 0 30px;
  border: none !important;
  font-size: 18px;
  color: #000;
}

.input-box {
  height: 60px;
  padding: 21px 0 0 30px;
  outline: none;
  resize: none;
  border: none !important;
  font-size: 18px;
  color: #000;
}

.system {
  width: 458px;
  padding: 10px 25px 10px;
  margin: 30px auto 10px;
  border: 1px solid #eceff4;
  color: #888888;
  font-size: 14px;
  font-weight: 400;
}

.system img {
  width: 30px;
  margin-right: 15px;
}

.rg-btn{
  position: absolute;
  left: 20px;
  top: -45px;
  padding: 4px 10px;
  font-size: 16px;
  color: #333333;
  border-radius: 5px;
  background: rgba(0,102,255,0.05);}
</style>
